﻿using DBA.Common;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Linq.Expressions;
using System.Reflection;

namespace DBA.Common.Test
{
    
    
    /// <summary>
    ///这是 AttributeHelperTest 的测试类，旨在
    ///包含所有 AttributeHelperTest 单元测试
    ///</summary>
    [TestClass()]
    public class AttributeHelperTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///获取或设置测试上下文，上下文提供
        ///有关当前测试运行及其功能的信息。
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region 附加测试特性
        // 
        //编写测试时，还可使用以下特性:
        //
        //使用 ClassInitialize 在运行类中的第一个测试前先运行代码
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //使用 ClassCleanup 在运行完类中的所有测试后再运行代码
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //使用 TestInitialize 在运行每个测试前先运行代码
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //使用 TestCleanup 在运行完每个测试后运行代码
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///Get 的测试
        ///</summary>
        public void GetTestHelper<T, TModel>()
        {
            //AttributeHelper<T> target = new AttributeHelper<T>(); // TODO: 初始化为适当的值\
            string expected = "方法1";
            var tmp1 = AttributeHelper.SetAttribute<DescriptionAttribute>();; // TODO: 初始化为适当的值
            string actual = String.Empty;
            DescriptionAttribute tmp = tmp1.Get<TModel>("GetString");
            //DescriptionAttribute tmp = AttributeHelper.GetAAttribute<DescriptionAttribute, Test>(p => p.Name);
            OrmPropertyAttribute tmp2 = AttributeHelper.GetAAttribute<OrmPropertyAttribute, TestOne>();
            OrmPropertyAttribute tmp3 = AttributeHelper.GetAAttribute<OrmPropertyAttribute, TestOne>( p => p.GroupGuid);
            OrmPropertyAttribute tmp4 = AttributeHelper.GetAAttribute<OrmPropertyAttribute, TestOne>(p => p.RoleGuid);
            OrmPropertyAttribute tmp5 = AttributeHelper.GetAAttribute<OrmPropertyAttribute, TestOne>(p => p.UserGuid);

            TestOne t1 = new TestOne();
            t1.GroupGuid = "234";
            t1.RoleGuid = "3434";
            t1.UserGuid = "345545";

            PropertyHelper.FindByName<TestOne>("GroupGuid", t1, false);
            PropertyHelper.FindProName<TestOne>("GroupGuid", t1);

            PropertyInfo[] pro = typeof(TModel).GetProperties();
            foreach (PropertyInfo propertyInfo in pro)
            {
            }

            actual = ((DescriptionAttribute)tmp).Description;
            Assert.AreEqual(expected, actual);  
        }

        [TestMethod()]
        public void GetTest()
        {
            GetTestHelper<DescriptionAttribute, Test>();
        }

        /// <summary>
        ///Get 的测试
        public void GetTest1Helper<T, TModel>()
        {
            string expected = "MyTest";
            var tmp1 = AttributeHelper.SetAttribute<T>(); ; // TODO: 初始化为适当的值
            string actual = String.Empty;
            PropertyInfo[] pro = typeof(TModel).GetProperties();
            //var tmp = AttributeHelper.GetAAttribute<T, TModel>();
            foreach (PropertyInfo propertyInfo in pro)
            {
                //AttributeHelper.GetAAttribute<OrmPropertyAttribute, TestOne>(propertyInfo.Name).
            }
            
            actual = (AttributeHelper.GetAAttribute<T, TModel>() as OrmPropertyAttribute).TableName;
            Assert.AreEqual(expected, actual); 
        }

        [TestMethod()]
        public void GetTest1()
        {
            GetTest1Helper<OrmPropertyAttribute, TestOne>();
        }

        ///// <summary>
        /////Get 的测试
        /////</summary>
        //public void GetTest2Helper<T, TModel>()
        //{
        //    AttributeHelper<T> target = new AttributeHelper<T>(); // TODO: 初始化为适当的值
        //    Expression<Func<TModel, object>> func = null; // TODO: 初始化为适当的值
        //    T expected = default(T); // TODO: 初始化为适当的值
        //    T actual;
        //    actual = target.Get<TModel>(func);
        //    Assert.AreEqual(expected, actual);
        //    Assert.Inconclusive("验证此测试方法的正确性。");
        //}

        //[TestMethod()]
        //public void GetTest2()
        //{
        //    GetTest2Helper<GenericParameterHelper, GenericParameterHelper>();
        //}
    }
}
